package pl.edu.agh.iosr.gamblingzone.model;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne; 

/**
 * The Class AbstractEvent.
 */

@AttributeOverride(name="id",
		column=@Column(name="AEVENT_ID"))
@Entity(name="ABSTRACT_EVENTS")
@Inheritance(strategy = InheritanceType.JOINED)
public class AbstractEvent extends EntityModel {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 8378003020104933128L;

	/** The closing date. */
	@Column(name="AEVENT_CLOSING_DATE", nullable=false)
	private Date closingDate;
	
	/** The creation date. */
	@Column(name="AEVENT_CREATION_DATE", nullable=false)
	private Date creationDate = new Date();
	
	/** The winner. */
	@OneToOne
	@JoinColumn(name="AEVENT_WINNER", nullable=true)
	private Participant winner;
	
	/** The rates. */
	@ManyToMany
	private Map<Double, Participant> rates = new HashMap<Double, Participant>();
	
	/** The group. */
	@ManyToOne//(targetEntity=Group.class)
	@JoinColumn(name="GROUP_ID")//, nullable=true)
	private Group group;
	
	/**
	 * Gets the rates.
	 * 
	 * @return the rates
	 */
	public Map<Double, Participant> getRates() {
		return rates;
	}

	
	/**
	 * Adds the participant.
	 * 
	 * @param participant the participant
	 * @param rate the rate
	 */
	public void addParticipant(Participant participant, Double rate) {
		this.rates.put(rate, participant);
	}
	
	/**
	 * Sets the rates.
	 * 
	 * @param rates the rates
	 */
	public void setRates(Map<Double, Participant> rates) {
		this.rates = rates;
	}

	/**
	 * Gets the group.
	 * 
	 * @return the group
	 */
	public Group getGroup() {
		return group;
	}

	/**
	 * Sets the group.
	 * 
	 * @param group the new group
	 */
	protected void setGroup(Group group) {
		this.group = group;
	}

	/**
	 * Gets the winner.
	 * 
	 * @return the winner
	 */
	public Participant getWinner() {
		return winner;
	}

	/**
	 * Sets the winner.
	 * 
	 * @param winner the new winner
	 */
	public void setWinner(Participant winner) {
		this.winner = winner;
	}

	/**
	 * Gets the closing date.
	 * 
	 * @return the closing date
	 */
	public Date getClosingDate() {
		return closingDate;
	}

	/**
	 * Sets the closing date.
	 * 
	 * @param closingDate the new closing date
	 */
	public void setClosingDate(Date closingDate) {
		this.closingDate = closingDate;
	}

	/**
	 * Gets the creation date.
	 * 
	 * @return the creation date
	 */
	public Date getCreationDate() {
		return creationDate;
	}

	/**
	 * Sets the creation date.
	 * 
	 * @param creationDate the new creation date
	 */
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}
}
